package org.luckystrophe.snowtoms.model.impl;

import org.luckystrophe.snowtoms.CoachActivity_;
import org.luckystrophe.snowtoms.R;
import org.luckystrophe.snowtoms.model.CoachMarks;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;

import com.googlecode.androidannotations.annotations.EBean;
import com.googlecode.androidannotations.api.sharedpreferences.BooleanPrefField;

@EBean
public class CoachMarksImpl implements CoachMarks {

	private int coachImageNumber;

	private Context context;

	private BooleanPrefField isFirstShow;

	@Override
	public void showCoachMark(Context context, int coachImageNumber, BooleanPrefField isFirstShow) {
		this.coachImageNumber = coachImageNumber;
		this.context = context;
		this.isFirstShow = isFirstShow;
		checkFirstShow();
	}

	private void checkFirstShow() {
		if (isFirstShow.get()) {
			showFirstCoachMarks();
			isFirstShow.put(false);
		}
	}

	private void showFirstCoachMarks() {
		Intent i = new Intent(context, CoachActivity_.class);
		i.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
		i.putExtra("coachImageNumber", coachImageNumber);

		((Activity) context).startActivity(i);
		((Activity) context).overridePendingTransition(R.anim.fadein, R.anim.fadeout);
	}

}
